#include <Windows.h>
#include <DbgHelp.h>

#pragma comment(lib,"dbghelp.lib" )

LONG __stdcall TopLevelExecptionHandler( _EXCEPTION_POINTERS* pExceptionInfo  )
{
	HANDLE hFile = ::CreateFile( "dumpfile.dmp", GENERIC_WRITE, 0, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
    if( hFile != INVALID_HANDLE_VALUE)
    {
         MINIDUMP_EXCEPTION_INFORMATION einfo;
         einfo.ThreadId = ::GetCurrentThreadId();
         einfo.ExceptionPointers = pExceptionInfo;
         einfo.ClientPointers = FALSE;
        ::MiniDumpWriteDump(::GetCurrentProcess(), ::GetCurrentProcessId(), hFile, MiniDumpNormal, &einfo, NULL, NULL);
        ::CloseHandle(hFile);
     }
	return EXCEPTION_EXECUTE_HANDLER;
}

int main(int argc, char *argv[])
{
	SetUnhandledExceptionFilter( TopLevelExecptionHandler );
	
	int *p = 0;
	*p = 0;
	return 0;
}